package cn.zyq.ykb.controller.mgt.customer;

import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.beans.customer.Customer;
import cn.zyq.ykb.service.customer.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客服电话Controller
 *
 * @author SystemAuth
 * @date 2023-05-22
 */

@RestController(value = "MgtCustomerController")
@RequestMapping("/mgt/customer")
@Api(tags = "客服电话接口")
public class CustomerController extends BaseController {

    @Autowired
    private CustomerService customerService;

    /**
     * 查询客服电话列表
     */
    @ApiOperation(value = "列表", response = Customer.class)
    @PreAuthorize("@ss.hasPermi('ykb:customer:list')")
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.customerService.selectCustomerList(pageParam);
    }

     /**
      * 导出客服电话列表
      */
     @ApiOperation(value = "导出")
     @PreAuthorize("@ss.hasPermi('ykb:customer:export')")
     @Log(title = "客服电话" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, Customer customer) {
         List<Customer> list = customerService.selectCustomerList(customer);
         ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer. class);
         util.exportExcel(response, list, "客服电话数据");
     }

    /**
     * 获取客服电话详细信息
     */
    @ApiOperation(value = "详情", response = Customer.class)
    @PreAuthorize("@ss.hasPermi('ykb:customer:query')")
    @GetMapping(value = "/{id}")
    public Object getInfo(@PathVariable("id") Integer id) {
        return this.customerService.selectCustomerByCustomerID(id);
    }
    /**
     * 获取客服电话详细信息
     */
    @ApiOperation(value = "详情", response = Customer.class)
    @PreAuthorize("@ss.hasPermi('ykb:customer:query')")
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.customerService.selectCustomerByServiceID(serviceID);

    }

    /**
     * 新增客服电话
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('ykb:customer:add')")
    @Log(title = "客服电话", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody Customer customer) {
        return this.customerService.insertCustomer(customer);
    }

    /**
     * 修改客服电话
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('ykb:customer:edit')")
    @Log(title = "客服电话", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody Customer customer) {
        return this.customerService.updateCustomer(customer);
    }

    /**
     * 删除客服电话
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('ykb:customer:remove')")
    @Log(title = "客服电话", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Object remove(@PathVariable Integer[] ids) {
        return this.customerService.deleteCustomerByCustomerIDs(ids);
    }
}
